package com.dgh.school.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.dgh.school.bean.Paper;
import com.dgh.school.common.R;
import com.dgh.school.mapper.PaperMapper;
import com.dgh.school.service.PaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PaperServiceImpl implements PaperService {

    @Autowired
    private PaperMapper paperMapper;

    @Override
    public R selectByPage(int pageNum, int pageSize) throws Exception {
        PageHelper.startPage(pageNum, pageSize);
        // 查询全部数据
        List<Paper> papers = paperMapper.selectAll();
        // 借助分页助手，获得分页信息
        PageInfo<Paper> pageInfo = new PageInfo<>(papers);

        return R.ok().setDate("pageInfo", pageInfo);
    }

    @Override
    public void deleteById(int id) throws Exception {
        paperMapper.deleteById(id);
    }

    @Override
    public void insertData(Paper paper)  {
        try {
            paperMapper.insert(paper);
        } catch (Exception e) {
            e.getMessage();
        }
    }

    @Override
    public void updateData(Paper paper) throws Exception {
        paperMapper.update(paper);
    }
}
